package com.bookstore.mapper;

import com.bookstore.entity.Comments;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CommentsMapper {
    int deleteByPrimaryKey(String commentId);

    int insert(Comments record);

    int insertSelective(Comments record);

    Comments selectByPrimaryKey(String commentId);

    int updateByPrimaryKeySelective(Comments record);

    int updateByPrimaryKey(Comments record);

    /**
     * 更新显示评论
     */
    int updateShow(@Param("show")Integer show,@Param("commentId")String commentId);

    /**
     * 分页后去评论
     */
    List<Comments> getCommentsByPage(@Param("start")Integer start,@Param("pageEnd")Integer pageEnd);

    /**
     * 获取总的记录数
     */
    int countComments();

    /**
     * 获取图书的评分来计算推荐的书
     * @return
     */
    List<Comments> getComments(@Param("userId")Long  userId);

    /**
     * 获取评论的人的个数
     * @return
     */
    Integer userCount();

    /**
     * 根据图书的id获得评论
     * @param bookId
     * @return
     */
    @Select("SELECT COMMENT_ID, DATE_TIME,INCLUDE,SCORE,NICKNAME,PHOTO,users.U_ID FROM " +
            "COMMENTS LEFT JOIN USER_ users ON USER_ID = users.U_ID WHERE BOOK_ID=#{bookId} ORDER BY DATE_TIME")
    @ResultMap("commentsShow")
    List<Comments> getCommentsByBookId(@Param("bookId")String bookId);

    int delComments(@Param("commentId") String commentId);

    int delCommentsByBookId(@Param("bookID")String bookID);
}